import axios from './axios.js'

function getLocation(){
    let location =JSON.parse(localStorage.getItem('local_city')) 
    if(!location){
        return new Promise((resolve,reject)=>{
            try{
                let bdCity=new window.BMap.LocalCity()
                bdCity.get(async res=>{
                    let result=await axios.get('/area/info?name='+res.name)
                    console.log(result,'9999-----jieko --------city')
                    localStorage.setItem('local_city',JSON.stringify(result.data.body))
                    resolve(result.data.body)
                })
            }catch(e){
                reject(e)
            }
        })
        
    }else{
        return Promise.resolve(location)
    }
}

export default getLocation